<article id="wikiArticle">
<div> <div class="blockIndicator obsolete obsoleteHeader"><p><strong><span class="icon-only-inline" title="This is an obsolete API and is no longer guaranteed to work."><i class="icon-trash"> </i></span> 已废弃</strong><br/>This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.</p></div></div>
<p><code><strong>clear()</strong></code> 方法用于删除 <code>WeakSet</code> 对象的所有元素，但是已经不是 ECMAScript 的一部分了。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript"><em>ws</em>.clear();</code></pre>
<h2 id="示例">示例</h2>
<h3 id="使用_clear方法">使用 <code>clear方法</code></h3>
<pre><code class="language-js example-bad">var ws = new WeakSet();

ws.add(window);
ws.has(window);  // true

ws.clear();

ws.has(window); // false
</code></pre>
<h2 id="规范">规范</h2>
<p>没有规范或草案。该方法原本计划包括在 ECMAScript 6，但是在草案 revision 28 (October 14, 2014) 被抛弃了。浏览器原先的实现不久后也被移除了，它从来不是标准的一分子。</p>
<h2 id="浏览器支持">浏览器支持</h2>
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
            This compatibility table still uses the old format,
            because we haven't yet converted the data it contains.
            <strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div><p></p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>36</td>
<td><span style="color: #f00;">未实现</span> [1]</td>
<td><span style="color: #f00;">未实现</span></td>
<td>23</td>
<td><span style="color: #f00;">未实现</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span> [1]</td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
</tr>
</tbody>
</table>
</div>
<p>[1] Added to Firefox in version 34, but removed in version 46. See <a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1101817" rel="noopener" title="FIXED: Remove Weak{Map,Set}.prototype.clear">bug 1101817</a>.</p>
<h2 id="相关">相关</h2>
<ul>
<li><a href="Reference/Global_Objects/WeakSet" title="WeakSet 对象允许你将弱保持对象存储在一个集合中。"><code>WeakSet</code></a></li>
<li><a href="Reference/Global_Objects/WeakSet/delete" title="delete() 方法从 WeakSet 对象中移除指定的元素。"><code>WeakSet.prototype.delete()</code></a></li>
</ul>
</article>